{include('Layout/header')}


<div class='site-content'>
    <div class='arts-border'>
        {if $noart != true} {/php}
        <h1>{$art['title']}</h1>
        <div class='art-mesg'>
            <p>
                <a href='#comment' class='art-mesg-btn'>
                    <span class='glyphicon glyphicon-comment art-mesg-icon' aria-hidden='true'></span>
                    {$totalComment} comment
                </a>
                <a href="{\Rexzy::url('author/')}{$art['author']}" class='art-mesg-btn'>
                    <span class='glyphicon glyphicon-user art-mesg-icon' aria-hidden='true'></span>
                    {$art['author']}
                </a>
                <span class='glyphicon glyphicon-list art-mesg-icon art-sort-icon' aria-hidden='true'></span>
                {foreach $art['sortname'] $key $val}
                    <a href="{$sortUrl}{$art['sortslugname'][$key]}" class='art-sort'>{$val}</a>
                {/foreach}
                <a href="{\Rexzy::url('date/')}{$art['date']}" class='art-mesg-btn'>
                    <span class='glyphicon glyphicon-time art-mesg-icon' aria-hidden='true'></span>
                    {$art['date']}
                </a>
            </p>
        </div>
        <div class='art-content'>
            {$art['content']}
        </div>
        <a name='comment' id='comment'> </a>
        <div class='comments'>

            <div>
                <h3 class='comment-num'>{$totalComment} 条评论</h3>
            </div>
            {php}
            function displayComment( $comments, $depth ) { 
            echo "<ol class='comment-list'>";
                foreach( $comments as $key => $val ) {
                    echo "<li";
                    if ( $depth % 2 ) {
                    echo " class='first-comment' ";
                    } else {
                    echo " class='second-comment' ";
                    }
                    echo ">";
                    echo "<div class='comment-author'><p>" . $val['name'] . "</p></div>";
                    echo "<div class='comment-meta'><p>" . $val['date'] . "</p></div>";
                    echo "<div class='comment-content'><p>" . $val['content'] . "</p></div>";
                    echo "<div class='comment-reply'><a href='#' data-parent=" . $val['commentid'] . ">回复</a></div>";
                    if( ( is_array($val['children']) ) && ( count($val['children']) > 0 ) ) {
                    echo "<div class='comment-children'>";
                        displayComment( $val['children'] , $depth + 1 );
                        echo "</div>";
                    }
                    echo "</li>";
                }
                echo "</ol>";
            }
            displayComment( $comments, 1 );
            {/php}

            <div id="new_comment_border">
                <div class="cancel-comment-reply">
                    <a href="#" id="cancel-comment-reply-btn">取消回复</a>
                </div>
                <h3>新评论</h3>
                <form id="new_comment" action="{\Rexzy::url('newcomment')}" method="post">
                    <div class="form-group">
                        <label for="name">怎么称呼</label>
                        <input type="text" class="form-control input-sm" id="name" >
                    </div>
                    <div class="form-group">
                        <label for="email">邮件地址</label>
                        <input type="email" class="form-control input-sm" id="email">
                    </div>
                    <div class="form-group">
                        <label for="commentval">评论</label>
                        <textarea class="form-control new-comment-content" rows="5" id='commentval'></textarea>
                    </div>
                    <input type='hidden' name='artid' value="{$art['artid']}" id='artid'/>
                    <input type='hidden' name='parent' value="0" id='parent'/>
                    <button type="submit" class="btn btn-default publish">发表</button>
                </form>
            </div>
        </div>
        {else}
        <div class="noart">
            <h2>没找到 ‘{$title}’ 的文章</h2>
        </div>
        {php}{/if}
    </div>  
</div>




<script>
    $(function () {
        $('.comment-reply > a').each(function () {
            this.onclick = function () {
                $(this).parent().after($('#new_comment_border'));
                $('.cancel-comment-reply').css('display', 'block');
                $('#new_comment_border').addClass('replying');
                var parent = $(this).attr('data-parent');
                $('#parent').attr('value', parent);
                return false;
            }
        });
    });

    $(function () {
        $('#cancel-comment-reply-btn').click(function () {
            $('.comments').append($('#new_comment_border'));
            $('.cancel-comment-reply').css('display', 'none');
            $('#new_comment_border').removeClass('replying');
            $('#parent').attr('value', 0);
            return false;
        });
    });

    // 用户信息更新成功后跳转函数
    function updateLocation() {
        location = "{\Rexzy::url('art/')}{$art['title']}.html";
    }

    formVerification('#new_comment', [
        {
            id: 'name',
            required: true,
            errormessage: '请输入称呼',
        },
        {
            id: 'email',
            required: true,
            errormessage: '请输入邮箱地址',
        },
        {
            id: 'commentval',
            required: true,
            errormessage: '请输入评论内容',
        },
        {
            id: 'parent',
            required: true,
            errormessage: '',
        },
        {
            id: 'artid',
            required: true,
            errormessage: '',
        },
    ], updateLocation);
</script>

{include('Layout/footer')}